<link href="/stylesheets/tabheader.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function single_check_all(){
  if(document.getElementById('single_check').checked==true){
    <%@running_stocks.each do |r|%>
      document.getElementById('running_<%=r.id%>').checked = true;
    <%end%>
  }else{
    <%@running_stocks.each do |r|%>
      document.getElementById('running_<%=r.id%>').checked = false;
    <%end%>
  }
}
</script>
<table width="100%" class="noborder_padding">
  <tr>
    <td width="200px" valign="top">
      <%=render :partial=>"sidemenu"%>
    </td>
    <td valign="top" style="padding-left: 10px;">
      <%=render :partial=>"tabheader"%>
      <h3><font color="#804040">Setting & Run</font></h3>
      <form action="/project/result_page_save" method="post" name="resultform">
      <div align="right">
        <span id="spinner" style="display:none;">Now Running! ...<img src="/images/spinner.gif"/></span>
        Note: <input type="text" style="width:300px;" name="remark" id="remark"/>
        <span id="runbt">
          <input type="button" value="Run" onclick="document.getElementById('runbt').style.display = 'none'; document.getElementById('spinner').style.display = ''; <%=remote_function(:url=>{:controller=>"project",:action=>"result_page_save2"}, :update=>"result_area", :with => "'remark='+$('remark').value", :complete=>"document.getElementById('runbt').style.display = ''; document.getElementById('spinner').style.display = 'none';")%>"/>
        </span>
      </div>
      <span id="result_area">
      Results<%if @word%><font color="red"><i> &nbsp;&nbsp;&nbsp; "<%=@word%>"</i></font><%end%><br/>
      <div align="right"><%=will_paginate @results%></div>
      <table width="100%" class="basic_table">
        <tr align="center">
          <th>RunID</th>
          <th>N</th>
          <th>Note</th>
          <th>Run At</th>
          <th></th>
        </tr>
        <%@results.each_with_index do |r,i|%>
        <tr align="center">
          <td><%=r.id%></td>
          <td><%=r.total_data%></td>
          <td align="left" width="300px">
            <span id="remark_area_<%=r.id%>">
              <%=r.remark%>
              <img src="/images/apply.gif" alt="Edit" title="Edit" style="cursor:pointer; vertical-align:middle;" onclick="<%=remote_function(:url=>{:controller=>"project",:action=>"edit_remark",:id=>"#{r.id}"}, :update=>"remark_area_#{r.id}")%>"/>
            </span>
          </td>
          <td><%=r.created_at%></td>
          <td>
            <a href="/project/view_result/<%=r.id%>" target="_blank">ViewResult</a> &nbsp;
            <%= link_to "Delete",  {:action => "result_delete", :id => r.id}, :confirm => "Are you sure?" %>
          </td>
        </tr>
        <%end%>
      </table>
      </span>
      <br/>
      Setting<br/>
      <table width="100%" class="noborder">
        <tr>
          <td valign="top" width="40%">
            <table class="basic_table" width="100%" border="1">
              <tr>
                <th colspan="2">Model</th>
              </tr>
              <tr>
                <td width="10px"></td>
                <td><input type="checkbox" name="mm_flag" <%if @project_setting.mm_flag=='Y'%>checked<%end%>/> Market Model</td>
              </tr>
              <tr>
                <td></td>
                <td><input type="checkbox" name="sw_flag" <%if @project_setting.sw_flag=='Y'%>checked<%end%>/> Scholes-Williams &nbsp; ( &#177;<input type="text" style="width:20px;" name="leadlag_size" value="<%=@project_setting.leadlag_size%>"/> )</td>
              </tr>
              <tr>
                <td></td>
                <td><input type="checkbox" name="bn_flag" <%if @project_setting.bn_flag=='Y'%>checked<%end%>/> Beveridge-Nelson Decomposition</td>
              </tr>
              <tr>
                <td></td>
                <td>
                  <input type="checkbox" name="hm_flag" <%if @project_setting.hm_flag=='Y'%>checked<%end%>/> Hamada
                  &nbsp; ( Tax Rate: <input type="text" name="tax_rate" style="width:40px;" value="<%=@project_setting.tax_rate%>"/> )
                </td>
              </tr>
            </table><br/>
            <center>
              <input type="submit" name="save_setting" id="save_setting" value="Save Setting"/>
            </center>
          </td>
          <td width="2%"></td>
          <td valign="top" width="58%">
            <table class="basic_table" width="100%" border="1">
              <tr>
                <th colspan="2">Test</th>
              </tr>
              <tr align="center">
                <td>
                  <i><b>Parametric</b></i>
                </td>
                <td>
                  <i><b>Non-Parametric</b></i>
                </td>
              </tr>
              <tr>
                <td style="padding-left:10px" valign="top">
                  <input type="checkbox" name="aar_diagram" <%if @project_setting.aar_diagram=='Y'%>checked<%end%>/> AAR Diagram<br/>
                  <input type="checkbox" name="caar_diagram" <%if @project_setting.caar_diagram=='Y'%>checked<%end%>/> CAAR Diagram<br/>
                  <input type="checkbox" name="aar_t" <%if @project_setting.aar_t=='Y'%>checked<%end%>/> AAR t-test<br/>
                  <input type="checkbox" name="caar_t" <%if @project_setting.caar_t=='Y'%>checked<%end%>/> CAAR t-test<br/>
                  <input type="checkbox" name="sd_ar_test" <%if @project_setting.sd_ar_test=='Y'%>checked<%end%>/> Standardized abnormal return<br/>
                  <input type="checkbox" name="sd_cr_test" <%if @project_setting.sd_cr_test=='Y'%>checked<%end%>/> Standardized cross-sectional return<br/>
                  <input type="checkbox" name="ar" <%if @project_setting.ar=='Y'%>checked<%end%>/> Show AR<br/>
                  <input type="checkbox" name="car" <%if @project_setting.car=='Y'%>checked<%end%>/> Show CAR
                </td>
                <td style="padding-left:10px" valign="top" style="border-left-style:solid; border-left-width:1px; border-left-color:#000000;">
                  <input type="checkbox" name="sign_test" <%if @project_setting.sign_test=='Y'%>checked<%end%>/> Sign Test<br/>
                  <input type="checkbox" name="rank_test" <%if @project_setting.rank_test=='Y'%>checked<%end%>/> Rank Test
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <br/>
      Stocks (N: <font color="red"><%=@filter_stock_count%></font>)
      <%groups = UserRunningStock.find(:all, :conditions=>["project_id=?", session[:selected_project_id]], :order=>"name")%>
      &nbsp;&nbsp;&nbsp; Save Group As : <input type="text" name="group_name" id="group_name" style="width:100px;"/> <input type="submit" name="save_group" id="save_group" value="Save"/>
      &nbsp;&nbsp;&nbsp; Group : 
        <select name="selected_group_id" id="selected_group_id" style="width:100px">
          <option value="0">--None--</option>
          <%groups.each do |g|%>
            <option value="<%=g.id%>" <%if g.use_flag=='Y'%>selected<%end%>><%=g.name%></option>
          <%end%>
        </select>
        <input type="submit" name="select_group" id="select_group" value="Select"/>
        <input type="submit" name="update_group" id="update_group" value="Update"/>
        <input type="submit" name="delete_group" id="delete_group" value="Delete"/>
      <br/>
      <table class="noborder" width="100%">
        <tr>
          <td valign="top" width="70%">
            <table class="basic_table" width="100%" border="1">
              <tr align="center">
                <th>Include <input type="checkbox" name="single_check" id="single_check" value="yes" onclick="single_check_all();" checked/></th><th>Type</th><th>Symbol</th><th>Event Date</th>
              </tr>
              <tr align="center" bgcolor="#8FC4E8">
                <td>Market</td>
                <td><%=@market_stock_type%></td>
                <td><%=@market_stock.s_symbol%></td>
                <td></td>
              </tr>
              <%@running_stocks.each do |r|%>
                <%
                  stock = nil
                  stock_type = ""
                  if r.stock_type=='S'
                    stock_type = "System's"
                    stock = Stock.find(:first, :conditions=>["id=?",r.stock_id])
                  else
                    stock_type = "Yours"
                    stock = UserStock.find(:first, :conditions=>["id=?",r.user_stock_id])
                  end
                %>
                <%if stock%>
                <tr align="center">
                  <td><input type="checkbox" id="running_<%=r.id%>" name="running_<%=r.id%>" <%if r.running=='Y'%>checked<%end%>/></td>
                  <td><%=stock_type%></td>
                  <td><%=stock.s_symbol%></td>
                  <td><%=r.event_date.to_s%></td>
                  <td></td>
                </tr>
                <%end%>
              <%end%>
            </table>
          </td>
          <td valign="top" align="center"></td>
        </tr>
      </table>
      </form>
    </td>
  </tr>
</table>